package com.sphd.beautysalon.fragments;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.sphd.beautysalon.base.LazyLoadFragment;
import com.sphd.beautysalon.base.RestaurantUrl;
import com.sphd.beautysalon.info.RestaurantInfo;
import com.sphd.beautysalon.utils.EwmUtil;
import com.sphd.beautysalon.R;
import com.sphd.beautysalon.utils.ScreenShot;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Hu on 2016/12/27.
 */

public class EwmFragment extends LazyLoadFragment {
    int pos;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.erweima_img)
    ImageView erweimaImg;
    @BindView(R.id.share_friend)
    Button shareFriend;
    EwmUtil ewmUtil;
    RestaurantInfo restaurantInfo;

    @Override
    public int getLayout() {
        return R.layout.ewm_fragment;
    }

    @Override
    public void initViews(View rootView) {
        ButterKnife.bind(this, rootView);

        ewmUtil = new EwmUtil();
        if (pos == 0) {
            title.setText("管理端");
            creatEwm(RestaurantUrl.EWMDownload, R.mipmap.ic_launcher_small);
        } else {
            title.setText("用户端");
            creatEwm("" +
                    restaurantInfo.getId(), R.mipmap.yonghu);
        }

    }

    private void creatEwm(String url, int imageId) {
        Bitmap qrBitmap = ewmUtil.generateBitmap(url, 400, 400);
        Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), imageId);
        Bitmap bitmap = ewmUtil.addLogo(qrBitmap, logoBitmap);
        erweimaImg.setImageBitmap(bitmap);
    }

    @Override
    public void loadData() {

    }

    public void setPageNo(int i, RestaurantInfo restaurantInfo) {
        this.pos = i;
        this.restaurantInfo = restaurantInfo;

    }



    @OnClick(R.id.share_friend)
    public void onClick() {
        ScreenShot.shoot(getActivity(),new File(Environment.getExternalStorageDirectory() + File.separator + "screenshot.jpg"));

    }






}
